package com.ymatou.iapi.csim.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.OfflineBean;
import com.ymatou.iapi.csim.service.OfflineCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*A客服主动转接给B客服
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Offline{
	private static OfflineBean bean;
	private static OfflineCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("A客服主动转接给B客服");
	}

	@Before
	public void caseUp() {
		bean=new OfflineBean();
		call=new OfflineCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_offline_001() {
		Logger.start(true,"客服下线-1:正常退出");
		try {
			//查询是否有在线客服 1，2
			ymt_onlinecs onlinecs1 =service.getOnlineCS();
			bean.setOffLineType(1);//下线类型(1：正常退出 2：浏览器关闭 3：客户端超时)
			bean.setSocketIoToken(onlinecs1.getSocketIoToken());//	socket标识
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库
			int count=onlinecsWapper.selectBy_Count(MapUtil.hashMap("CSId",csId));
			Logger.verifyEquals(0,count, "验证当前客服不存在数据库onlinecs表中");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_offline_002() {
		Logger.start(true,"客服下线-2:浏览器关闭 ");
		try {
			//查询是否有在线客服 1，2
			ymt_onlinecs onlinecs1 =service.getOnlineCS();
			bean.setOffLineType(2);//下线类型(1：正常退出 2：浏览器关闭 3：客户端超时)
			bean.setSocketIoToken(onlinecs1.getSocketIoToken());//	socket标识
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库
			int count=onlinecsWapper.selectBy_Count(MapUtil.hashMap("CSId",csId));
			Logger.verifyEquals(0,count, "验证当前客服不存在数据库onlinecs表中");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_offline_003() {
		Logger.start(true,"客服下线-3:客户端超时 ");
		try {
			//查询是否有在线客服 1，2
			ymt_onlinecs onlinecs1 =service.getOnlineCS();
			bean.setOffLineType(3);//下线类型(1：正常退出 2：浏览器关闭 3：客户端超时)
			bean.setSocketIoToken(onlinecs1.getSocketIoToken());//	socket标识
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals("0",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals("",call.getResult().get("ErrorMessage"), "验证返回的errorMessage");
			Logger.verifyEquals(true,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("200",call.getStatus(), "验证返回的status");
			//验证数据库
			int count=onlinecsWapper.selectBy_Count(MapUtil.hashMap("CSId",csId));
			Logger.verifyEquals(0,count, "验证当前客服不存在数据库onlinecs表中");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_offline_004() {
		Logger.start(true,"客服下线-SocketIoToken不存在 ");
		try {
			//查询是否有在线客服 1，2
			bean.setOffLineType(4);//下线类型(1：正常退出 2：浏览器关闭 3：客户端超时)
			bean.setSocketIoToken("11");//	socket标识
			call.setData(bean);
			call.callService();		
			Logger.verifyEquals("2",call.getResult().get("ErrorCode").toString(), "验证返回的errorCode");
			Logger.verifyEquals(true,call.getResult().get("ErrorMessage").toString().contains("socketiotoken not exists"), "验证返回的errorMessage");
			Logger.verifyEquals(false,call.getResult().get("Success"), "验证返回的Success");
			Logger.verifyEquals("500",call.getStatus(), "验证返回的status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}